package com.apping.module.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.apping.module.R;
import com.umeng.analytics.MobclickAgent;

public class MajorDialogAtv extends Activity {
	private SelectEvent m_selectEvent;
	private Class<?> m_cls;
	private Intent m_intent;

	public void initUI() {
		Button button1 = (Button) findViewById(R.id.alert_dialog);
		button1.setOnClickListener(m_selectEvent);

		Button button2 = (Button) findViewById(R.id.alert_dialog_with_editText);
		button2.setOnClickListener(m_selectEvent);

		Button button3 = (Button) findViewById(R.id.alert_dialog_with_MultiChoiceItems);
		button3.setOnClickListener(m_selectEvent);

		Button button4 = (Button) findViewById(R.id.alert_dialog_with_SingleChoiceItems);
		button4.setOnClickListener(m_selectEvent);

		Button button5 = (Button) findViewById(R.id.alert_dialog_with_Items);
		button5.setOnClickListener(m_selectEvent);
	}

	public void NextAtv() {
		m_intent.setClass(getApplication(), m_cls);
		startActivity(m_intent);
		this.finish();
	}

	public void SetNextAtv(Class<?> cls) {
		m_cls = cls;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.apping_dialog);
		m_selectEvent = new SelectEvent(this);
		m_intent = new Intent();
		initUI();
	}

	public void onResume() {
		super.onResume();
		MobclickAgent.onPageStart("SplashScreen"); // 统计页面
		MobclickAgent.onResume(this); // 统计时长
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPageEnd("SplashScreen"); // 保证 onPageEnd 在onPause
													// 之前调用,因为 onPause 中会保存信息
		MobclickAgent.onPause(this);
	}
}

class SelectEvent implements OnClickListener {
	private MajorDialogAtv m_atv;

	public SelectEvent(MajorDialogAtv atv) {
		m_atv = atv;
	}

	@Override
	public void onClick(View v) {
		int id;
		id = v.getId();
		if (id == R.id.alert_dialog) {
			createCommonAlertDialog();
		}

		if (id == R.id.alert_dialog_with_editText) {
			createAlertDialogWithEditText();
		}

		if (id == R.id.alert_dialog_with_MultiChoiceItems) {
			createAlertDialogWithMultiChoiceItems();
		}

		if (id == R.id.alert_dialog_with_SingleChoiceItems) {
			createAlertDialogWithSingleChoiceItems();
		}

		if (id == R.id.alert_dialog_with_Items) {
			createAlertDialogWithItems();
		}

	}

	public void createCommonAlertDialog() {
		AlertDialog.Builder builder = new AlertDialog.Builder(m_atv);
		builder.setTitle("提示");
		builder.setMessage("确定退出？");

		builder.setPositiveButton("确定",
				new android.content.DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
		builder.setNegativeButton("取消",
				new android.content.DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
		builder.create();
		builder.show();
	}

	public void createAlertDialogWithEditText() {
		AlertDialog.Builder builder = new AlertDialog.Builder(m_atv);
		builder.setTitle("请输入");
		builder.setView(new EditText(m_atv));
		builder.setPositiveButton("确定", null);
		builder.setNegativeButton("取消", null);
		builder.create();
		builder.show();
	}

	public void createAlertDialogWithMultiChoiceItems() {
		AlertDialog.Builder builder = new AlertDialog.Builder(m_atv);
		builder.setTitle("请选择");
		builder.setMultiChoiceItems(new String[] { "One", "Two", "Three" },
				null, null);
		builder.setPositiveButton("确定", null);
		builder.setNegativeButton("取消", null);
		builder.show();
	}

	public void createAlertDialogWithSingleChoiceItems() {
		AlertDialog.Builder builder = new AlertDialog.Builder(m_atv);
		builder.setTitle("请选择");
		builder.setSingleChoiceItems(new String[] { "One", "Two", "Three" }, 0,
				null);
		builder.setPositiveButton("确定", null);
		builder.setNegativeButton("取消", null);
		builder.show();
	}

	public void createAlertDialogWithItems() {
		AlertDialog.Builder builder = new AlertDialog.Builder(m_atv);
		builder.setTitle("列表框");
		builder.setItems(new String[] { "One", "Two", "Three" }, null);
		builder.setPositiveButton("确定", null);
		builder.setNegativeButton("取消", null);
		builder.show();
	}
}
